const env = require("./env")

export default {
  // Global page headers: https://go.nuxtjs.dev/config-head
  head: {
    title: "云联二手机",
    meta: [
      { charset: "utf-8" },
      { name: "viewport", content: "width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1" }, //解决移动端缩放问题
      {
        hid: "description",
        name: "description",
        content: "云联二手机，三一唯一指定的官方二手机"
      },
      { name: "format-detection", content: "telephone=no" }
    ],
    link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
    script: [{ src: "https://hm.baidu.com/hm.js?95747c44606e9aec652c2da4d83fe9ac" }]
  },

  // Global CSS: https://go.nuxtjs.dev/config-css
  css: [
    // "@/assets/theme/index.css",
    "@/assets/styles/reset.scss",
    "@/assets/styles/element-variables.scss",
    "@/assets/styles/common.scss",
    "vue-mini-player/lib/vue-mini-player.css",
    "mescroll.js/mescroll.min.css",
    "swiper/css/swiper.css"
  ],
  loading: false,
  // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
  // fix import "@/plugins/main.js"; document is not defined
  plugins: [
    "@/plugins/element-ui",
    "@/plugins/api/request.js",
    "@/plugins/api/api.js",
    "@/plugins/utils/options.js",
    "@/plugins/utils/yunlian-stat.js",
    "@/plugins/i18n.js",
    "@/plugins/push.js",
    { src: "@/plugins/baidu-statistics", ssr: false },
    { src: "@/plugins/player.js", ssr: false },
    { src: "@/plugins/mescroll.js", ssr: false },
    { src: "@/plugins/copy-text.js", ssr: false },
    { src: "@/plugins/vue-swiper.js", ssr: false }
  ],
  // { src: "@/plugins/main.js", ssr: false }

  // Auto import components: https://go.nuxtjs.dev/config-components
  components: true,

  // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
  buildModules: [],

  // Modules: https://go.nuxtjs.dev/config-modules
  modules: [
    "@nuxtjs/axios",
    "cookie-universal-nuxt"
    // ["cookie-universal-nuxt", { parseJSON: true }],
  ],

  env: {
    baseUrl: env[process.env.NODE_ENV].BASE_API,
    NODE_ENV: process.env.NODE_ENV
  },

  axios: {
    // proxy: true,
    retry: { retries: 3 },
    withCredentials: true,
    baseUrl: env[process.env.NODE_ENV].BASE_API
  },

  router: {
    mode: "history",
    middleware: ["adapter", "i18n"],
    extendRoutes(routers) {
      routers.push({
        path: "/",
        redirect: "/home"
      })
    }
  },

  // proxy: {
  //   "/api": {
  //     target: env[process.env.NODE_ENV].BASE_API,
  //     changeOrigin: true,
  //   },
  // },

  // Build Configuration: https://go.nuxtjs.dev/config-build
  build: {
    transpile: [/^element-ui/],
    vendor: ["axios"], //防止重复打包
    babel: {
      plugins: [
        [
          "component",
          {
            libraryName: "element-ui",
            styleLibraryName: "theme-chalk"
          }
        ]
      ]
    },
    postcss: {
      postcssOptions: {
        plugins: {
          "postcss-px-to-viewport-8-plugin": {
            unitToConvert: "px", // 要转换的单位
            viewportWidth: 1920, // 设计稿宽度
            unitPrecision: 5, // 单位转换后保留的精度
            propList: ["*"], // 指定转换那些属性，* 表示全部
            viewportUnit: "vw", // 希望使用的视口单位
            fontViewportUnit: "vw", // 字体使用的视口单位
            selectorBlackList: [], // 要忽略的选择器
            minPixelValue: 1, // 最小的转换数值
            mediaQuery: false, // 是否在媒体查询中也转换px
            replace: true, // 是否直接更换属性值
            exclude: /(\/|\\)(node_modules)(\/|\\)/ // 忽略某些文件夹下的文件或者某些特定文件
          }
        }
      }
    },
    extractCSS: true // Nuxt3 Vite在全局引入css文件后 页面有大量内联style的真正解决办法  https://blog.csdn.net/qq_37436987/article/details/132914249
  }
  // Nuxt3 Vite在全局引入css文件后 页面有大量内联style的真正解决办法  https://blog.csdn.net/qq_37436987/article/details/132914249
  // experimental: { inlineSSRStyles: false }
  // 如何删除nuxt项目中的window.__nuxt__,对我来说太大了https://devpress.csdn.net/vue/632c1bf6357a883f870c7cb3.html
  // hooks: {
  //   "vue-renderer:ssr:context"(context) {
  //     const routePath = JSON.stringify(context.nuxt.routePath)
  //     context.nuxt = { serverRendered: true, routePath }
  //   }
  // }
}
